package com.amazon.trietree.server;

import java.io.IOException;

import javax.servlet.ServletException;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import org.eclipse.jetty.server.Request;
import org.eclipse.jetty.server.handler.AbstractHandler;

/**
 * Created with IntelliJ IDEA.
 * User: Tylaar
 * Date: 11/8/12
 * Time: 2:12 PM
 * Company: Amazon.com
 */
public class MetaDataJettyHandler extends AbstractHandler {
    private MetaDataServerNode selfNode;

    public MetaDataServerNode getSelfNode() {
        return selfNode;
    }

    public void setSelfNode(MetaDataServerNode selfNode) {
        this.selfNode = selfNode;
    }

    public void handle(String target, Request baseRequest, HttpServletRequest request, HttpServletResponse response)
            throws IOException, ServletException {
        System.out.println("received a req.");
        response.setContentType("text/html;charset=utf-8");
        response.setStatus(HttpServletResponse.SC_OK);
        baseRequest.setHandled(true);
        response.getWriter().println("<h1>Hello World</h1>");
        response.getWriter().println("<li>Request url: " + target + "</li>");
        response.getWriter().println("<li>Server port: " + request.getServerPort() + "</li>");
    }
}